package design_pattern.open_close;


/**
 * @Name : open_close.GraphiceEditor
 * @Description : 描述
 * Created by cyd on 2020-12-14 13:49:40
 */
public class GraphicEditor {
    public void drawShape(Shape s) {
        if (s.m_type == 1) {
            drawRetangle(s);
        } else if (s.m_type == 2) {
            drawCircle(s);
        } else if (s.m_type == 3) {
            //增加画三角形的判断
            drawTringle(s);
        }
    }

    private void drawTringle(Shape s) {
        System.out.println("绘制三角形");
    }

    private void drawCircle(Shape s) {
        System.out.println("绘制矩形");
    }

    //增加画三角形的方法
    private void drawRetangle(Shape s) {
        System.out.println("绘制圆形");
    }
}

class Shape {
    int m_type;
}

class Rectangle extends Shape {
    Rectangle() {
        super.m_type = 1;
    }
}

class Circle extends Shape {
    Circle() {
        super.m_type = 2;
    }
}

//增加三角形的类
class Triangle extends Shape {
    Triangle() {
        super.m_type = 3;
    }
}

class Tester {
    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Rectangle());
        //调用画三角形方法
        graphicEditor.drawShape(new Triangle());
    }
}
